import type {
  BaseEntity,
  CheckedSelectTree,
  ID,
  IDS,
  PageQuery,
  PageResult,
} from '#/api/common';

import { requestClient } from '#/api/request';

export interface SysRole extends BaseEntity {
  roleId: ID;
  roleName: string;
  dataScope: string;
  roleSort: number;
  status: string;
  isMenuDisplay: boolean;
  isDeptDisplay: boolean;
}

const baseUrl = '/ur_biz/sys_role';

/** 查询角色列表 */
export function listRole(params: PageQuery) {
  return requestClient.get<PageResult<SysRole>>(`${baseUrl}/list`, { params });
}

/** 根据角色ID查询菜单下拉树结构 */
export function menuTreeSelect(roleId?: ID) {
  return requestClient.get<CheckedSelectTree>(
    `${baseUrl}/menu_checked_select_tree/${roleId ?? ''}`,
  );
}

/** 根据角色ID查询部门下拉树结构 */
export function deptTreeSelect(roleId?: ID) {
  return requestClient.get<CheckedSelectTree>(
    `${baseUrl}/dept_checked_select_tree/${roleId ?? ''}`,
  );
}

/** 角色详情 */
export function getRole(id: ID) {
  return requestClient.get(`${baseUrl}/${id}`);
}

/** 新增角色 */
export function addRole(data: any) {
  return requestClient.post(`${baseUrl}/add`, data);
}

/** 修改角色 */
export function editRole(data: any) {
  return requestClient.post(`${baseUrl}/edit`, data);
}

/** 删除角色 */
export function delRole(roleIds: IDS) {
  return requestClient.post(`${baseUrl}/remove`, roleIds);
}

/** 用户状态修改 */
export function changeStatus(id: ID, status: string) {
  return requestClient.post(`${baseUrl}/edit_status`, {
    id,
    status,
  });
}
